package tt.lab.pmbok.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import tt.lab.pmbok.model.Inout;
import tt.lab.pmbok.model.PmbokProcess;
import tt.lab.pmbok.model.Tool;

public class ProcessDaoHibernate  implements ProcessDao {
	@Resource(name = "sessionFactory")
	private SessionFactory sessionFactory;
	
/*	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}*/
	private Session getSession(){
		return sessionFactory.getCurrentSession();
	}
	
	public PmbokProcess load(int id) {
		return (PmbokProcess) getSession().load(PmbokProcess.class, id);
	}

	public List<PmbokProcess> loadByGroupArea(int groupId, int areaId) {
		Query query;
		if (groupId > 0 & areaId > 0) {
			query = getSession().createQuery("from PmbokProcess where groupId = :groupId and areaId = :areaId");
			query.setInteger("groupId", groupId);
			query.setInteger("areaId", areaId);
		} else {
			query = getSession().createQuery("from PmbokProcess");
		}

		List<PmbokProcess> list = (List<PmbokProcess>) query.list();
		return list;
	}

	public Inout loadInout(int id) {
		return (Inout) getSession().load(Inout.class, id);
	}

	public Tool loadTool(int id) {
		return (Tool) getSession().load(Tool.class, id);
	}

}
